package Example9_9;


import java.awt.event.*;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.util.StringTokenizer;
import java.io.*;
import java.util.*;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import javax.swing.text.JTextComponent;

public class HandleListener implements ActionListener {
	JTextArea inputText, showText;

	public void setInputText(JTextArea text) {
		inputText = text;
	}

	public void setShowText(JTextArea text) {
		showText = text;
	}

	public void actionPerformed(ActionEvent e) {
		String str = e.getActionCommand();
		if (str.equals("copy"))
			showText.copy();
		else if (str.equals("cut"))
			showText.cut();
		else if (str.equals("paste"))
			inputText.paste();
		else if (str.equals("baocui")) {
			JOptionPane.showMessageDialog(null, "ɹ","Ϣ",JOptionPane.INFORMATION_MESSAGE);

			
			File fWrite = new File("e:\\save.txt");
			try {Writer out = new FileWriter(fWrite);//ļд
				BufferedWriter bufferWrite = new BufferedWriter(out);
				
				String str1 = null;
				str1 = inputText.getText();
					StringTokenizer fenxi = new StringTokenizer(str1);
					int count = fenxi.countTokens();
					
					bufferWrite.write(str1);
					bufferWrite.newLine();
				bufferWrite.close();
				out.close();

			} catch (IOException e1) {
				System.out.println(e1.toString());
			}
			
			
			
			
			
		} else if (str.equals("open")) {
			File fRead = new File("e:\\\\save.txt");
			try {
				Reader ins = new FileReader(fRead);
				BufferedReader bufferReads = new BufferedReader(ins);
				String po = null;
				while ((po = bufferReads.readLine()) != null) {
					showText.append(po);
				}
			} catch (IOException e1) {
				System.out.println(e1.toString());
			}
		}
	}
}